package com.ias.agdis_r.adapter;

import java.util.List;

import com.ias.agdis_r.bean.fight.FlightQueryValue;
import com.ias.agdis_r.view.flight.FlightStateView;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.BaseAdapter;

public class SearchDetailActivityListViewAdapter extends BaseAdapter {

	private static final LayoutParams LIST_ITEM_LAYOUT_PARAM = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT);

	private List<FlightQueryValue> data;
	Context context;

	public SearchDetailActivityListViewAdapter(Context context, List<FlightQueryValue> data) {

		this.data = data;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		// TODO 此种方法加载更多的时候ListView顺序错乱，暂时采用下侧方法解决
		if (convertView == null) {// 如果加载item布局为null
			convertView = new FlightStateView(context, LIST_ITEM_LAYOUT_PARAM, null);
		}
		FlightStateView stateView = (FlightStateView) convertView;
		stateView.setFlightQueryValue(data.get(position));
		return stateView;

		// return new FlightStateView(context, LIST_ITEM_LAYOUT_PARAM,
		// data.get(position));
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

}
